# 设置为科大的镜象,参考 https://mirrors.ustc.edu.cn/help/crates.io-index.html:
function set_mirror_ustc() {
    file_path="$HOME/.cargo/config.toml"
    touch $file_path || true
    cat <<EOF >$file_path
[source.crates-io]
replace-with = 'ustc'

[source.ustc]
registry = "git://mirrors.ustc.edu.cn/crates.io-index"
EOF
}

# 设置为字节的镜象，官网 https://rsproxy.cn/:
function set_mirror_bytedance() {
    file_path="$HOME/.cargo/config.toml"
    touch $file_path || true
    cat <<EOF >$file_path
[source.crates-io]
# To use sparse index, change 'rsproxy' to 'rsproxy-sparse'
replace-with = 'rsproxy'

[source.rsproxy]
registry = "https://rsproxy.cn/crates.io-index"
[source.rsproxy-sparse]
registry = "sparse+https://rsproxy.cn/index/"

[registries.rsproxy]
index = "https://rsproxy.cn/crates.io-index"

[net]
git-fetch-with-cli = true
EOF

}

function set_mirror_all() {
    file_path="$HOME/.cargo/config.toml"
    touch $file_path || true
    cat <<EOF >$file_path

# 官方:
[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"

# 替换成你偏好的镜像源
replace-with = 'sjtu'
#replace-with = 'ustc'

# 清华大学
[source.tuna]
registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"

# 中国科学技术大学
[source.ustc]
registry = "git://mirrors.ustc.edu.cn/crates.io-index"

# 上海交通大学
[source.sjtu]
registry = "https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index"

# rustcc社区
[source.rustcc]
registry = "git://crates.rustcc.cn/crates.io-index"


EOF
}
